package com.duleme.servlet;

import com.duleme.common.EncodeUtils;
import com.duleme.common.JsonUtils;
import com.duleme.entity.*;
import com.duleme.service.CartService;
import com.duleme.service.ShopService;
import com.duleme.service.impl.CartServiceImpl;
import com.duleme.service.impl.ShopServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.stream.events.EndDocument;
import java.io.IOException;

@WebServlet(name = "UserOrderServlet",urlPatterns = "/user/order")
public class UserOrderServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        EncodeUtils.setEncoding(request,response);
        User user = (User) request.getSession().getAttribute("user");
        /*User user = new User();
        user.setUserId(100020);*/
        ShopService shopService = new ShopServiceImpl();
        AllOrder allOrder = shopService.getAllOrder(user.getUserId());
        if (allOrder!=null){
            String json = JsonUtils.object2Json(allOrder);
            System.out.println(json);
            response.getWriter().write(json);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        EncodeUtils.setEncoding(request,response);
        CartService cartService = new CartServiceImpl();
        User user = (User) request.getSession().getAttribute("user");
        //cartService.placeOrder(user.getUserId());
    }
}
